﻿using Caching;
using Newtonsoft.Json;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Utilities.Redis;

namespace RedisService
{
  
    public class Program
    {
        private static readonly RedisBaseHelp _redis = new RedisBaseHelp();

        private static readonly Common _comon = new Common();

        public static void Main(string[] args)
        {



            var corporationId = Guid.Parse("e3a803b7-7df9-4602-b380-554676c471da");
            int i = 0;
            while (i <= 999)
            {
                Random rd = new Random();
                var rand = rd.Next(0, 15);
                Console.WriteLine("存储数据到库" + rand);
                var stslist = CacheManager.GetAsync(
                     RedisCacheKeys.StudentsJson(corporationId, rand, i),
                     async () => await GetStudents());
                Console.WriteLine("数据");
                Console.WriteLine(JsonConvert.SerializeObject(stslist));
                i++;
            }



            Console.WriteLine();
        }

        public class Students {
            public Guid Id { get; set; }
            public string StuName { get; set; }
            public int Age { get; set; }

        }


        public static async  Task<List<Students>> GetStudents() {
            
            var sts = new List<Students>() {
                new Students() {Id =Guid.NewGuid(),StuName="张三001",Age=16 },
                  new Students() {Id =Guid.NewGuid(),StuName="张三002",Age=17 },
                    new Students() {Id =Guid.NewGuid(),StuName="张三003",Age=18 },
                      new Students() {Id =Guid.NewGuid(),StuName="张三004",Age=19 },
                        new Students() {Id =Guid.NewGuid(),StuName="张三005",Age=20 },
                          new Students() {Id =Guid.NewGuid(),StuName="张三006",Age=21 },
                            new Students() {Id =Guid.NewGuid(),StuName="张三007",Age=22 },
                              new Students() {Id =Guid.NewGuid(),StuName="张三008",Age=23},

            };
            return sts;

        }
    }
}